import 'dart:convert';

import 'package:bruno/bruno.dart';
import 'package:get/get.dart';

import '../../entrance/route/routes.dart';
import '../../global/user/logic.dart';
import '../../global/user/state.dart';
import '../../utils/httputils/api.dart';
import '../../utils/httputils/resultdata.dart';
import 'state.dart';

class LoginLogic extends GetxController {
  final LoginState state = LoginState();
  final userState = UserState();
  final userCtrl = UserController();

  login(String loginName,String loginPassword) async{
    if (loginName.trim().isEmpty) {
      return BrnToast.show('请输入账号',Get.context!);
    }

    if (loginPassword.trim().isEmpty) {
      return BrnToast.show('请输入密码',Get.context!);
    }
    var params = {
      'appCode': "jx-clivil-servant-assessment",
      'loginName': loginName,
      'loginPassword': loginPassword,
      'loginType': '1',
      'platType': '1',
    };

    ResultData response = await Api.login(params);

    if (response.isSuccess) {
      await userCtrl.loginSuccess(response.data);

      Get.offAllNamed(RouterPath.main);
    }
  }
}
